<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Requests\LinksRequest;
use App\Http\Controllers\Controller;
use App\Model\Links;
use Session,Input;

class LinksController extends CommonController
{
    // 显示添加友情链接页面
    public function index()
    {
        $linksList = Links::show(60);
        return view('home.links.index', compact('linksList'));
    }
    
    // 申请链接
    public function store(Request $request)
    {
        $data = Input::except('_token');
        $request = new LinksRequest();
        $errors = $request->validateInput($data);
        
        if($errors->all()){
            $info = $errors->first();
            return response()->json(['status'=>0, 'info'=>$data]);
        }
        
        $res = Links::insert($data);
        if(false !== $res){
            return response()->json(['info'=>'已提交申请，等待管理员审核', 'status'=>1]);
        } else {
            return response()->json(['info'=>'提交申请失败，请重试', 'status'=>0]);
        }
    }
}